<?php
require_once "./db_config.php";
$arr=[];
$offset=$_POST['offset'];
$rowsOfPage=$_POST['rowsOfPage'];
$offset=($offset-1)*$rowsOfPage;
$name=$_POST['name'];
$dept=$_POST['dept'];
$ryxz=$_POST['ryxz'];
$status=$_POST['status'];
$state=$_POST['state'];
$outgoing=$_POST['outgoing'];
if($name==''){
    $nameInfo='';
}else{
    $nameInfo="and (姓名 LIKE '%".$name."%' or 工号 LIKE '%".$name."%' or 档案编号 LIKE '%".$name."%')";
}
if($dept==''){
    $deptInfo='';
}else{
    $deptInfo="and 科室='$dept'";
}
if($ryxz==''){
    $ryxzInfo='';
}else{
    $ryxzInfo="and ryxz='$ryxz'";
}
if($state==''){
   $stateInfo='';
}else{
    if($state=="0"){
        $stateInfo="and state is null";
    }else{
        $stateInfo="and state='$state'";
    }
}
if($status=='在职'){
    $outgoingInfo='';
}else{
    if($outgoing==''){
        $outgoingInfo="and outgoing is not null";
    }else{
        $outgoingInfo="and outgoing='$outgoing'";
    }
}
class DATA{
    public $count=0;
    public $data=[];
}
$data=new DATA;
$result = mysqli_query($conn, "set names utf8");
$sql = "SELECT 姓名 FROM personalfiles WHERE 1=1 $nameInfo  $deptInfo  $ryxzInfo  $stateInfo $outgoingInfo ";
$result = mysqli_query($conn, $sql);
$data->count=mysqli_num_rows($result);
$sql = "SELECT * FROM personalfiles WHERE 1=1 $nameInfo  $deptInfo  $ryxzInfo  $stateInfo $outgoingInfo limit $offset,$rowsOfPage";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    // 输出数据
    while($row = mysqli_fetch_assoc($result)) {
        $arr[]=$row;
    }
} else {
    echo "0 结果";
}
$data->data=$arr;
echo json_encode($data,JSON_UNESCAPED_UNICODE);
mysqli_close($conn);
?>
